home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / msgout.c < prev    next >
C/C++ Source or Header  |  1994-11-15  |  20KB  |  902 lines

  1. /*
  2. *                msgout.c
  3. *
  4. * External Message writer.  For use with external OtherNet parsers.
  5. */
  6. /*
  7. *                history
  8. *
  9. * 92Jan17 HAW  1.4 - Hard-wire room name to msgs; handle domain field.
  10. * 91Mar26 HAW  1.3 - Virtual rooms.
  11. * 89Sep25 HAW  1.2 - update for Route Mail.
  12. * 88Nov17 HAW  Created.
  13. */
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "ctdl.h"
  17. #include "2ndfmt.h"
  18. #include "stdarg.h"
  19. #include "dos.h"
  20. #include "math.h"
  21. /*
  22. *                contents
  23. *
  24. */
  25. #define TITLE        "C86Net Message Extracter(Amiga)"
  26. #define VERSION        "V3.42"
  27. #define NO_ERROR    0
  28. #define BAD_ARGS    1
  29. #define BAD_TABLE    2
  30. #define NO_NODE        3
  31. #define FATAL        4
  32. #define BAD_OUT_FILE    5
  33. #define LF_ERROR    6
  34. FILE        *outfile;
  35. extern FILE *upfd;
  36. extern CONFIG       cfg;            /* Configuration variables    */
  37. extern MessageBuffer msgBuf;    /* The -sole- message buffer    */
  38. extern aRoom       roomBuf;        /* Room buffer */
  39. extern logBuffer   logBuf;
  40. extern FILE       *roomfl, *logfl;
  41. extern int       thisRoom;    /* Current room       */
  42. extern rTable       *roomTab;
  43. extern struct mBuf mFile1, mFile2;
  44. extern SListBase Serves;
  45. extern NetTable    *netTab;
  46. extern NetBuffer   netBuf, netTemp;
  47. extern FILE       *netfl;
  48. extern LogTable    *logTab;
  49. extern FILE       *msgfl, *msgfl2;
  50. FILE       *GlobalFd, *netMisc;
  51. static int RCount, SCount;
  52. extern int       thisNet;       /* Current node in use       */
  53. char *R_SH_MARK =  "&&";
  54. char *NON_LOC_NET= "%%";
  55. char *LOC_NET =    "++";
  56. char inNet = ANYTIME_NET;
  57. #ifdef ANSI_PROTOTYPING
  58. void NetField(char field, char *value);
  59. void MsgOutGenInit(void);
  60. void MODoVirtuals(void);
  61. void Process(void);
  62. int  FindNet(label nm);
  63. int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  64. char *room);
  65. void UtilRoomSend(int rover, char *send1, char *send2, char *send3);
  66. void HandleMessage(char *addr1, char *addr2, char *addr3);
  67. int  RoutePath(char *rp, char *str);
  68. char FindMessage(SECTOR_ID loc, MSG_NUMBER id);
  69. void NetFormat(void);
  70. void NowRouteMail(void);
  71. void MoutCC();
  72. void MoutForeign();
  73. int ReadRoutedDest(int c);
  74. int ReadRouted(void);
  75. #endif
  76. void Intel32ToMotorola(UNS_32 *);
  77.  
  78. int  mPrintf(char *format, ...) {return 0; }  /* stub to quiet the linker */
  79.  
  80.  
  81. /*
  82. * crashout()
  83. *
  84. * Crash exit handler.
  85. */
  86. void crashout(str)
  87. char *str;
  88.   {
  89.   printf(str);
  90.   writeSysTab();
  91.   exit(FATAL);
  92.  
  93.   }
  94. /*
  95. * main()
  96. *
  97. * Main manager
  98. */
  99. int  main(int, char **);
  100. int  main(argc, argv)
  101. char **argv;
  102. int  argc;
  103.   {
  104.   int rover;
  105.   extern char *WRITE_ANY;
  106.   printf("%s %s\n%s\n\n", TITLE, VERSION, COPYRIGHT);
  107.   /* not enough arguments?  Explain. */
  108.   if (argc < 3)
  109.     {
  110.     printf("usage: MSGOUT nodename file\n");
  111.     exit(BAD_ARGS);
  112.  
  113.     }
  114.   cfg.weAre = UTILITY;
  115.   if (!readSysTab(TRUE, TRUE))
  116.     {
  117.     exit(BAD_TABLE);
  118.  
  119.     }
  120.   if (access(LOCKFILE, 0) != ERROR)
  121.     {
  122.     printf("Please do not run MsgOut using Outside Commands.\n");
  123.     exit(LF_ERROR);
  124.  
  125.     }
  126.   MsgOutGenInit();
  127.   VirtInit();
  128.   if (FindNet(argv[1]) == ERROR)
  129.     {
  130.     writeSysTab();
  131.     printf("Could not find node %s.\n", argv[1]);
  132.     exit(NO_NODE);
  133.  
  134.     }
  135.   if ((outfile = fopen(argv[2], WRITE_ANY)) == NULL)
  136.     {
  137.     writeSysTab();
  138.     printf("Couldn't open output file %s.\n", argv[2]);
  139.     exit(BAD_OUT_FILE);
  140.  
  141.     }
  142.   Process();
  143.   putNet(thisNet, &netBuf);
  144.   writeSysTab();
  145.   return 0;
  146.   }
  147. /*
  148. * MsgOutGenInit()
  149. *
  150. * This handles general initialization.
  151. */
  152. void MsgOutGenInit()
  153.   {
  154.   SYS_FILE fn;
  155.   initNetBuf(&netBuf);
  156.   initNetBuf(&netTemp);
  157.   makeSysName(fn, "ctdlnet.sys", &cfg.netArea);
  158.   openFile(fn, &netfl);
  159.   initRoomBuf(&roomBuf);
  160.   makeSysName(fn, "ctdlroom.sys", &cfg.roomArea);
  161.   openFile(fn, &roomfl);
  162.   InitMsgBase();
  163.  
  164.   }
  165. /*
  166. * Process()
  167. *
  168. * This is the main processor.
  169. */
  170. void Process()
  171.   {
  172.   char        *send1, *send2, *send3;
  173.   label        temp;
  174.   SYS_FILE        fn;
  175.   FILE        *mail;
  176.   int            rover;
  177.   extern char        *READ_ANY;
  178.   struct netMLstruct    buf;
  179.   /* first we handle Mail>. */
  180.   if (netBuf.nbflags.normal_mail)
  181.     {
  182.     sPrintf(temp, "%d.ml", thisNet);
  183.     makeSysName(fn, temp, &cfg.netArea);
  184.     if ((mail = fopen(fn, READ_ANY)) == NULL)
  185.       {
  186.       printf("WARNING: Couldn't open %s for mail delivery to %s.\n",
  187.       fn, netBuf.netName);
  188.  
  189.       }
  190.     else
  191.       {
  192.       while (getMLNet(mail, buf))
  193.       if (FindMessage(buf.ML_loc, buf.ML_id))
  194.         {
  195.         strCpy(msgBuf.mbroom, "Mail");
  196.         NetFormat();
  197.  
  198.         }
  199.       fclose(mail);
  200.       unlink(fn);        /* kill mail file */
  201.  
  202.       }
  203.     netBuf.nbflags.normal_mail = FALSE;
  204.  
  205.     }
  206.   NowRouteMail();        /* now handle any route mail */
  207.   /* now we handle the shared rooms */
  208.   for (rover = 0; rover < SHARED_ROOMS; rover++)
  209.     {
  210.     /* if we share this room, check for new msgs. */
  211.     if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  212.       {
  213.       getRoom(netRoomSlot(rover));
  214.       send1 = R_SH_MARK;
  215.       send2 = send3 = "guh";
  216.       switch (roomBuf.rbShareType)
  217.         {
  218.         case REG_HOST:
  219.         printf("WARNING: Please do not use Regional Host settings.\n");
  220.         printf("\nThey are obsolete.\n");
  221.         case PEON:
  222.         break;
  223.         case BACKBONE:
  224.         switch (netBuf.netRooms[rover].mode)
  225.           {
  226.           case PEON:
  227.           send2  = NON_LOC_NET;
  228.           break;
  229.           case ACTIVE_BACKBONE:
  230.           case PASS_BACKBONE:
  231.           case REG_HOST:
  232.           send2 = NON_LOC_NET;
  233.           send3 = LOC_NET;
  234.           break;
  235.           default: crashout("shared rooms: #2");
  236.  
  237.           }
  238.         break;
  239.         default: crashout("shared rooms: #1");
  240.  
  241.         }
  242.       UtilRoomSend(rover, send1, send2, send3);
  243.  
  244.       }
  245.  
  246.     }
  247.   MODoVirtuals();
  248.   UpdVirtStuff();
  249.  
  250.   }
  251. /*
  252. * UtilRoomSend()
  253. *
  254. * Send stuff out.
  255. */
  256. void UtilRoomSend(rover, send1, send2, send3)
  257. int rover;
  258. char *send1, *send2, *send3;
  259.   {
  260.   int i;
  261.   for (i = 0; i < MSGSPERRM; i++)
  262.     {
  263.     if (roomBuf.msg[i].rbmsgNo > netBuf.netRooms[rover].lastMess)
  264.       {
  265.       if (FindMessage(roomBuf.msg[i].rbmsgLoc, roomBuf.msg[i].rbmsgNo))
  266.         {
  267.         strcpy(msgBuf.mbroom, roomBuf.rbname);
  268.         HandleMessage(send1, send2, send3);
  269.  
  270.         }
  271.  
  272.       }
  273.  
  274.     }
  275.   netBuf.netRooms[rover].lastMess = roomTab[thisRoom].rtlastMessage;
  276.   netTab[thisNet].netTRooms[rover].lastMess =
  277.   roomTab[thisRoom].rtlastMessage;
  278.  
  279.   }
  280. /*
  281. * HandleMessage()
  282. *
  283. * This decides if a message should be sent out.
  284. */
  285. void HandleMessage(addr1, addr2, addr3)
  286. char *addr1, *addr2, *addr3;
  287.   {
  288.   if ((strncmp(msgBuf.mbaddr, addr1, strLen(addr1))
  289.   == SAMESTRING  ||
  290.   strncmp(msgBuf.mbaddr, addr2, strLen(addr2))
  291.   == SAMESTRING  ||
  292.   strncmp(msgBuf.mbaddr, addr3, strLen(addr3))
  293.   == SAMESTRING) &&
  294.   RoutePath(LOC_NET, msgBuf.mbaddr)     != thisNet &&
  295.   RoutePath(NON_LOC_NET, msgBuf.mbaddr) != thisNet)
  296.     {
  297.     NetFormat();
  298.  
  299.     }
  300.  
  301.   }
  302. /*
  303. * RoutePath()
  304. *
  305. * This function returns the number of the node that routed this msg
  306. * to here.  If the msg was not routed in from a BackBone, then
  307. * return ERROR, which will never match another node's #.
  308. * 88Oct13: Now simply check for msg origin, assume if one exists
  309. * that it should be checked.  Don't remember why it is restricted
  310. * to only BACKBONE-routed msgs.  Doesn't seem necessary.
  311. */
  312. int RoutePath(rp, str)
  313. char *str, *rp;
  314.   {
  315.   if (strncmp(rp, str, strLen(rp)) == SAMESTRING)
  316.     {
  317.     if (strLen(str) != strLen(rp)) /* prevent return of 0 */
  318.     return atoi(str + 2);
  319.  
  320.     }
  321.   return ERROR;
  322.  
  323.   }
  324. /*
  325. * FindNet()
  326. *
  327. * This function will find the named node.  Stolen from searchNameNet/NETMISC.
  328. */
  329. int  FindNet(nm)
  330. label nm;
  331.   {
  332.   int rover;
  333.   for (rover = 0; rover < cfg.netSize; rover++)
  334.     {
  335.     if (netTab[rover].ntflags.in_use &&
  336.     hash(nm) == netTab[rover].ntnmhash)
  337.       {
  338.       getNet(rover, &netBuf);
  339.       if (strCmpU(netBuf.netName, nm) == SAMESTRING)
  340.       return rover;
  341.  
  342.       }
  343.  
  344.     }
  345.   return ERROR;
  346.  
  347.   }
  348. /*********** These functions stolen & modified from MSG.C ***************/
  349. /*
  350. * FindMessage()
  351. *
  352. * This gets all set up to do something with a message.  We use this rather
  353. * than the findMessage in libmsg.c so we can automatically read in the 'M'
  354. * field.
  355. */
  356. char FindMessage(loc, id)
  357. SECTOR_ID  loc;        /* sector in message.buf */
  358. MSG_NUMBER id;        /* unique-for-some-time ID# */
  359.   {
  360.   MSG_NUMBER here;
  361.   startAt(msgfl, &mFile1, loc, 0);
  362.   do
  363.     {
  364.     getMessage(getMsgChar, FALSE, TRUE, TRUE);
  365.     here = atol(msgBuf.mbId);
  366.  
  367.     }
  368.   while (here != id &&  mFile1.thisSector == loc);
  369.   return (char) ((here == id));
  370.  
  371.   }
  372. /*
  373. * NetFormat()
  374. *
  375. * This function writes a message to disk.
  376. */
  377. void NetFormat()
  378.   {
  379.   MSG_NUMBER val;
  380.   if (!msgBuf.mborig[0])
  381.   strCpy(msgBuf.mborig, cfg.nodeId + cfg.codeBuf);
  382.   if (!msgBuf.mboname[0])
  383.   strCpy(msgBuf.mboname, cfg.nodeName + cfg.codeBuf);
  384.   if (!msgBuf.mbsrcId[0])
  385.     {
  386.     val = atol(msgBuf.mbId);
  387.     sPrintf(msgBuf.mbsrcId, "%ld %ld",
  388.     (val & 0xffff0000) >> 16, val & 0xffffl);
  389.  
  390.     }
  391.   if (msgBuf.mbauth[0]) NetField('A', msgBuf.mbauth);
  392.   if (msgBuf.mbdate[0]) NetField('D', msgBuf.mbdate);
  393.   if (msgBuf.mbtime[0]) NetField('C', msgBuf.mbtime);
  394.   if (msgBuf.mboname[0]) NetField('N', msgBuf.mboname);
  395.   if (msgBuf.mbdomain[0]) NetField('X', msgBuf.mbdomain);
  396.   if (msgBuf.mborig[0]) NetField('O', msgBuf.mborig);
  397.   if (msgBuf.mbroom[0]) NetField('R', msgBuf.mbroom);
  398.   if (msgBuf.mbsrcId[0]) NetField('S', msgBuf.mbsrcId);
  399.   if (msgBuf.mbto[0]) NetField('T', msgBuf.mbto);
  400.   if (msgBuf.mbOther[0]) NetField('P', msgBuf.mbOther);
  401.   RunList(&msgBuf.mbCC, MoutCC);
  402.   RunList(&msgBuf.mbForeign, MoutForeign);
  403.   NetField('M', msgBuf.mbtext);
  404.  
  405.   }
  406. /*
  407. * NetField()
  408. *
  409. * Work function to write out a field and its identifier.
  410. */
  411. void NetField(field, value)
  412. char *value, field;
  413.   {
  414.   fprintf(outfile, "%c%s", field, value);
  415.   putc(0, outfile);
  416.  
  417.   }
  418. /*
  419. * MoutCC()
  420. *
  421. * This handles the CC field of a message.
  422. */
  423. void MoutCC(dd)
  424. char *dd;
  425.   {
  426.   NetField('W', dd);
  427.  
  428.   }
  429. /*
  430. * MoutForeign()
  431. *
  432. * This handles the Foreign fields of a message.
  433. */
  434. void MoutForeign(dd)
  435. char *dd;
  436.   {
  437.   NetField(dd[0], dd + 1);
  438.  
  439.   }
  440. static int  RWorkBuf[7];
  441. /*
  442. * NowRouteMail()
  443. *
  444. * This function handles outgoing route mail.
  445. */
  446. void NowRouteMail()
  447.   {
  448.   int        rover;
  449.   label    temp;
  450.   SYS_FILE    fn;
  451.   extern char *READ_ANY, OverRides;
  452.   if (!netBuf.nbflags.HasRouted)
  453.   return;
  454.   for (rover = 0; rover <= netBuf.nbHiRouteInd; rover++)
  455.     {
  456.     sPrintf(temp, "R%d.%d", thisNet, rover);
  457.     makeSysName(fn, temp, &cfg.netArea);
  458.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  459.       {
  460.       getMsgStr(getNetChar, temp, NAMESIZE);
  461.       getMsgStr(getNetChar, temp, NAMESIZE);
  462.       StartDecode(ReadRoutedDest);
  463.       RCount = SCount = 0;
  464.       while (getMessage(ReadRouted, TRUE, TRUE, TRUE))
  465.         {
  466.         strCpy(msgBuf.mbroom, "Mail");
  467.         NetFormat();
  468.  
  469.         }
  470.       fclose(netMisc);
  471.       unlink(fn);
  472.  
  473.       }
  474.  
  475.     }
  476.   netBuf.nbflags.HasRouted = FALSE;
  477.   netBuf.nbHiRouteInd         = 0;
  478.  
  479.   }
  480. /*
  481. * ReadRoutedDest()
  482. *
  483. * A work function to read encrypted data.
  484. */
  485. int ReadRoutedDest(int c)
  486.   {
  487.   RWorkBuf[RCount++] = c;
  488.   return TRUE;
  489.  
  490.   }
  491. /*
  492. * ReadRouted()
  493. *
  494. * This function will read a routed char for getMessage().
  495. */
  496. int ReadRouted()
  497.   {
  498.   int c;
  499.   if (RCount != SCount)
  500.   return RWorkBuf[SCount++];
  501.   RCount = SCount = 0;
  502.   while (SCount == RCount && (c = fgetc(netMisc)) != EOF)
  503.   Decode(c);
  504.   if (RCount != SCount)
  505.   return RWorkBuf[SCount++];
  506.   if (c == EOF) StopDecode();
  507.   if (RCount != SCount)
  508.   return RWorkBuf[SCount++];
  509.   return -1;
  510.  
  511.   }
  512. /*
  513. * getNetChar()
  514. *
  515. * This function gets a character from a network temporary file.
  516. */
  517. int getNetChar()
  518.   {
  519.   int c;
  520.   c = fgetc(netMisc);
  521.   if (c == EOF) return -1;
  522.   return c;
  523.  
  524.   }
  525. #define WeServe(x)    SearchList(&Serves, x)
  526. /*
  527. * LocalName()
  528. *
  529. * This takes a string of form <system> _ <domain> and attempts to discover if
  530. * this domain mapped system is actually a local.  This is used when we're
  531. * sending mail and are trying to find out if a Who Else override needs to be
  532. * generated.  Ugly kludge, but, hey, that's what programming's all about, eh?
  533. */
  534. char *LocalName(char *system)
  535.   {
  536.   char *domain, *System;
  537.   if ((domain = strchr(system, '_')) == NULL) return system;
  538.   domain += 2;    /* always preceded by a space -- or so we assume */
  539.   if (strCmpU(domain, cfg.codeBuf + cfg.nodeDomain) == SAMESTRING ||
  540.   WeServe(domain) != NULL)
  541.     {
  542.     System = strdup(system);
  543.     if ((domain = strchr(System, ' ')) == NULL)
  544.     return system;    /* should never happen, though */
  545.     *domain = NULL;
  546.     if (searchNameNet(System, &netTemp) != ERROR)
  547.       {
  548.       free(System);
  549.       return netTemp.netName;
  550.  
  551.       }
  552.     free(System);
  553.  
  554.     }
  555.   return system;
  556.  
  557.   }
  558. /*
  559. * SepNameSystem()
  560. *
  561. * This will parse an Other Recipient spec.
  562. */
  563. char SepNameSystem(char *string, char *person, char *system, NetBuffer *buf)
  564.   {
  565.   char  *c;
  566.   label domain;
  567.   char dup, work[150];        /* should be sufficient */
  568.   int   slot;
  569.   strCpy(work, string);
  570.   if ((c = strchr(work, '@')) == NULL)
  571.     {
  572.     if (strLen(work) >= NAMESIZE) return BAD_FORMAT;
  573.     strCpy(person, string);
  574.     return NOT_SYSTEM;
  575.  
  576.     }
  577.   *c++ = 0;
  578.   NormStr(work);
  579.   NormStr(c);
  580.   if (strLen(c) >= NAMESIZE * 2 || strLen(work) >= NAMESIZE)
  581.   return BAD_FORMAT;
  582.   strCpy(system, c);
  583.   strCpy(person, work);
  584.   if (buf == NULL) return IS_SYSTEM;    /* very minor cheat - see CTDL.C */
  585.   if ((slot = searchNameNet(c, buf)) != ERROR)
  586.     {
  587.     /* try secondary lists */
  588.     strCpy(system, buf->netName);    /* get "real" name */
  589.     if (buf->nbflags.local)
  590.       {
  591.       return IS_SYSTEM;
  592.  
  593.       }
  594.  
  595.     }
  596.   if (SystemInSecondary(c, domain, &dup))
  597.     {
  598.     if (dup)
  599.       {
  600.       /* oops */
  601.       return (char) (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM;
  602.  
  603.       }
  604.     if (strCmpU(domain, cfg.nodeDomain + cfg.codeBuf) == SAMESTRING &&
  605.     (strCmpU(c, cfg.nodeName + cfg.codeBuf) == SAMESTRING ||
  606.     strCmpU(c, UseNetAlias(cfg.nodeName+cfg.codeBuf, TRUE))
  607.     == SAMESTRING))
  608.       {
  609.       printf("Hey, that's this system!\n ");
  610.       return SYSTEM_IS_US;
  611.  
  612.       }
  613.     sPrintf(system, "%s _ %s", c, domain);
  614.     return IS_SYSTEM;
  615.  
  616.     }
  617.   return (char) (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM;
  618.  
  619.   }
  620. static label SearchResult;
  621. static char  *SearchTarget, GetAlias;
  622. /*
  623. * UseNetAlias()
  624. *
  625. * This will find a usenet alias or the converse.
  626. */
  627. char *UseNetAlias(char *Name, char FindAlias)
  628.   {
  629.   void *EatTrans();
  630.   SListBase Dummy =
  631.     {
  632.     NULL, NULL, NULL, NULL, EatTrans
  633.  
  634.     };
  635.   SYS_FILE fn;
  636.   char *c, *WorkName;
  637.   WorkName = strdup(Name);    /* use a work buffer */
  638.   SearchResult[0] = 0;
  639.   SearchTarget = WorkName;
  640.   if (!FindAlias) while ((c = strchr(WorkName, ' ')) != NULL) *c = '_';
  641.   makeSysName(fn, "aliases.sys", &cfg.roomArea);
  642.   GetAlias = FindAlias;
  643.   MakeList(&Dummy, fn, NULL);    /* CHEAT!  WHEEEEEE! */
  644.   free(WorkName);
  645.   if (strLen(SearchResult) == 0) return Name;
  646.   if (FindAlias) while ((c = strchr(SearchResult, '_')) != NULL) *c = ' ';
  647.   return SearchResult;
  648.  
  649.   }
  650. /*
  651. * EatTrans()
  652. *
  653. * This will eat a line of input for alias processing.
  654. */
  655. void *EatTrans(char *line)
  656.   {
  657.   char *c;
  658.   if ((c = strchr(line, ' ')) != NULL)
  659.     {
  660.     *c = 0;
  661.     if (GetAlias)
  662.       {
  663.       /* check second field */
  664.       if (strCmpU(c + 1, SearchTarget) == SAMESTRING)
  665.         {
  666.         strCpy(SearchResult, line);
  667.  
  668.         }
  669.  
  670.       }
  671.     else
  672.       {
  673.       /* check first field */
  674.       if (strCmpU(line, SearchTarget) == SAMESTRING)
  675.         {
  676.         strCpy(SearchResult, c + 1);
  677.  
  678.         }
  679.  
  680.       }
  681.  
  682.     }
  683.   return NULL;
  684.  
  685.   }
  686. /*
  687. * SearchSecondary()
  688. *
  689. * This searches a secondary (domain) list for a system.
  690. */
  691. static char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup)
  692.   {
  693.   FILE *fd;
  694.   int  bucket;
  695.   char found, *tab, *c, *tab2;
  696.   char line[90];
  697.   JumpInfo JumpTable[BUCKETCOUNT];
  698.   if ((fd = fopen(secondary, READ_ANY)) == NULL)
  699.   return FALSE;
  700.   fread(line, VERS_SIZE + 1, 1, fd);
  701.   fread(JumpTable, sizeof JumpTable, 1, fd);
  702.   #ifdef IS_MOTOROLA
  703.   for (bucket = 0; bucket < BUCKETCOUNT; bucket++)
  704.   Intel32ToMotorola(&JumpTable[bucket].offset);
  705.   #endif
  706.   bucket = (isdigit(Name[0])) ? Name[0] - '0' :
  707.   toUpper(Name[0]) - 'A' + 10;
  708.   fseek(fd, JumpTable[bucket].offset, 0);
  709.   found = FALSE;
  710.   do
  711.     {
  712.     *isdup = FALSE;
  713.     if (fgets(line, sizeof line, fd) == NULL) break;
  714.     if ((tab2 = strchr(line, '\n')) != NULL)
  715.     *tab2 = 0;
  716.     if (strlen(line) == 0)
  717.       {
  718.       break;
  719.  
  720.       }
  721.     if (line[0] <= ' ')
  722.       {
  723.       switch (line[0])
  724.         {
  725.         case DUP:
  726.         *isdup = TRUE;
  727.         break;
  728.         default: printf("Ooop!");
  729.         break;
  730.  
  731.         }
  732.       c = line + 1;
  733.  
  734.       }
  735.     else c = line;
  736.     tab = strchr(c, '\t');
  737.     *tab++ = 0;
  738.     if (strCmpU(c, Name) == 0)
  739.     found = TRUE;
  740.     if (strCmpU(c, Name) > 0) break;
  741.  
  742.     }
  743.   while (!found);
  744.   if (found)
  745.     {
  746.     if ((tab2 = strchr(tab, '\t')) != NULL)
  747.     *tab2++ = 0;
  748.     strCpy(Domain, tab);
  749.     if (tab2 != NULL)    /* alias?  Copy it into search string */
  750.     strCpy(Name, tab2);
  751.  
  752.     }
  753.   fclose(fd);
  754.   return found;
  755.  
  756.   }
  757. /*
  758. * SystemInSecondary()
  759. *
  760. * This will look for a system in secondary lists.
  761. */
  762. char SystemInSecondary(char *Name, char *Domain, char *dup)
  763.   {
  764.   int rover;
  765.   char *sep;
  766.   SYS_FILE secondary;
  767.   label name;
  768.   char WorkName[(NAMESIZE * 2) + 1];
  769.   char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup);
  770.   strCpy(WorkName, Name);
  771.   /* is the domain specified already?  if so, parse it */
  772.   if ((sep = strchr(WorkName, '_')) != NULL ||
  773.   (sep = strchr(WorkName, '.')) != NULL)
  774.     {
  775.     *sep++ = 0;
  776.     NormStr(WorkName);
  777.     NormStr(sep);
  778.     if (strchr(sep, '_') != NULL ||
  779.     strchr(sep, '.') != NULL)
  780.     return FALSE;    /* no subdomains */
  781.     strCpy(Name, WorkName);
  782.     strCpy(Domain, sep);
  783.     *dup = FALSE;        /* by definition */
  784.     return TRUE;
  785.  
  786.     }
  787.   Domain[0] = 0;
  788.   for (rover = 0; rover < 100; rover++)
  789.     {
  790.     sPrintf(name, "nodes%d.fst", rover);
  791.     makeSysName(secondary, name, &cfg.netArea);
  792.     if (access(secondary, 0) != 0) break;
  793.     if (SearchSecondary(secondary, Name, Domain, dup)) break;
  794.  
  795.     }
  796.   strCpy(WorkName, Name);
  797.   /* make sure we found something and it's not us */
  798.   return (Domain[0] != 0 &&
  799.   strCmpU(Name, cfg.codeBuf + cfg.nodeName) != SAMESTRING &&
  800.   strCmpU(UseNetAlias(WorkName,FALSE), cfg.codeBuf + cfg.nodeName)
  801.   != SAMESTRING);
  802.  
  803.   }
  804. extern VirtualRoom *VRoomTab;
  805. extern VirtNet       *VirtNetList;
  806. extern char VirtualInUse;
  807. extern int  VirtSize, VNetSize;
  808. /*
  809. * MODoVirtuals()
  810. *
  811. * This sends rooms to another system, if needed.
  812. */
  813. void MODoVirtuals()
  814.   {
  815.   int rover, which, x;
  816.   if (!VirtualInUse) return ;
  817.   for (rover = 0; rover < VIRT_LIMIT; rover++)
  818.     {
  819.     x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  820.     if (x >= VirtSize || x < 0 || !VRoomInuse(x))
  821.     VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  822.     if (VirtNetList[thisNet].VirtList[rover].WhichVirt != -1)
  823.       {
  824.       SendVirtual(rover, NULL, NULL, NULL);
  825.  
  826.       }
  827.  
  828.     }
  829.  
  830.   }
  831. /*
  832. * SendVirtual()
  833. *
  834. * This manages sending a room to another system.
  835. */
  836. int SendVirtual(int VirtIndex, char *d1, char *d2, char *d3)
  837.   {
  838.   int    VirtNo, count;
  839.   MSG_NUMBER StartMsg;
  840.   VirtNo = VirtNetList[thisNet].VirtList[VirtIndex].WhichVirt;
  841.   /* Send all the new LD messages received */
  842.   StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LDSent;
  843.   count = ThrowAll(VirtNo, LD_DIR, StartMsg, VRoomTab[VirtNo].vrHiLD,
  844.   VRoomTab[VirtNo].vrName);
  845.   VirtNetList[thisNet].VirtList[VirtIndex].LDSent =
  846.   VRoomTab[VirtNo].vrHiLD;
  847.   if (VirtNetList[thisNet].VirtList[VirtIndex].mode != PEON)
  848.     {
  849.     StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LocSent;
  850.     count += ThrowAll(VirtNo, LOCAL_DIR, StartMsg,
  851.     VRoomTab[VirtNo].vrHiLocal, VRoomTab[VirtNo].vrName);
  852.     VirtNetList[thisNet].VirtList[VirtIndex].LocSent =
  853.     VRoomTab[VirtNo].vrHiLocal;
  854.  
  855.     }
  856.   VRoomTab[VirtNo].vrChanged |= SENT_DATA;
  857.   return count;
  858.  
  859.   }
  860. /*
  861. * ThrowAll()
  862. *
  863. * This sends a virtual room to another system.
  864. */
  865. static int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  866. char *room)
  867.   {
  868.   MSG_NUMBER  rover;
  869.   int        count=0;
  870.   char    fn[100];
  871.   extern char *READ_ANY;
  872.   extern PROTO_TABLE Table[];
  873.   extern int    TransProtocol;
  874.   for (rover = start + 1; rover <= end; rover++)
  875.     {
  876.     CreateVAName(fn, which, distance, rover);
  877.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  878.       {
  879.       while (getMessage(getNetChar, TRUE, TRUE, TRUE))
  880.         {
  881.         count++;
  882.         strCpy(msgBuf.mbroom, room);
  883.         NetFormat();
  884.  
  885.         }
  886.       fclose(netMisc);
  887.  
  888.       }
  889.  
  890.     }
  891.   return count;
  892.  
  893.   }
  894. void Intel32ToMotorola(UNS_32 *val)
  895.   {
  896.   unsigned long temp;
  897.   temp = *val;
  898.   *val = ((ULONG)(temp & 0xff) << 24) + ((ULONG)(temp & 0xff00) << 8) +
  899.   ((ULONG)(temp & 0xff0000) >> 8) + ((ULONG)(temp &0xff000000) >> 24);
  900.  
  901.   }
  902.